<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type='text/javascript' src='../js/vue.js'></script>
    <script type='text/javascript' src=''></script>

</head>

<body>
    <!-- 
        
      -->
    <div id="root">
        <h2>当前n值：{{n}}</h2>
        <button @click="add">点击+1</button>
        <button @click="bye">点击销毁vm</button>

    </div>
    <script>
        Vue.config.productionTip = false;

        new Vue({
            el: '#root',
            data: {
                n: 1
            },
            methods: {
                add() {
                    this.n++;
                },
                bye() {
                    console.log('bye')
                    this.$destroy()
                }
            },
            watch: {
                n() {
                    console.log('n变')
                }
            },
            beforeCreate() {
                console.log('beforeCreate')
            },
            created() {
                console.log('created')
            },
            beforeMount() {
                console.log('beforeMount')
            },
            beforeUpdate() {//页面和数据尚未同步
                console.log('beforeUpdate')
                console.log(this.n)
                // debugger
            },
            updated() {//页面和数据保持同步了
                console.log('updated')
                console.log(this.n)
                // debugger
            },
            beforeDestroy() {//vm上的data和methods都处于可用状态
                console.log('beforeDestroy')
                console.log(this.n)
            },
            destroyed() {//react没有
                console.log('destoryed')
            },
        })
    </script>
</body>

</html>